<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta HTTP-EQUIV="pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <meta HTTP-EQUIV="expires" CONTENT="0">
    <title>留言管理</title>
    <link rel="stylesheet" href="../../css/element.css">
    <link rel="stylesheet" href="../../css/base.css">
</head>
<body>
<div id="wrapper" v-cloak>
    <div style="padding-bottom: 10px">
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item @click.native="parent.changeIndex('index')">首页</el-breadcrumb-item>
            <el-breadcrumb-item>留言管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>

    <div style="height: 1px; margin: 10px 0; background-color: white"></div>

    <el-input v-model="search" style="width: 20%;" suffix-icon="el-icon-search" placeholder="请输入留言内容回车搜索" @keyup.enter.native="loadTable"></el-input>
<!--    <el-button @click="add" type="primary" size="mini" style="margin: 10px 0">新增</el-button>-->
    <el-button @click="exp" type="primary" size="mini" style="margin: 10px 0">批量导出</el-button>
    <el-table
            :data="tableData"
            border
            style="width: 100%">
        <el-table-column type="index" :index="parent.changeXuhao" label="序号" width="50"></el-table-column>
        <el-table-column prop="username" label="用户名"></el-table-column>
        <el-table-column prop="content" label="留言内容"></el-table-column>
        <el-table-column prop="time" label="留言时间"></el-table-column>
        <el-table-column
                fixed="right"
                label="操作"
                width="150">
            <template slot-scope="scope">
<!--                <el-button type="primary" @click="edit(scope.row)"  icon="el-icon-edit" circle size="mini"></el-button>-->
                <el-popconfirm
                        @onConfirm="del(scope.row.id)"
                        title="确定删除？"
                >
                    <el-button type="danger" icon="el-icon-delete" circle slot="reference" size="mini"></el-button>
                </el-popconfirm>
            </template>
        </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div style="background-color: white">
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pageNum"
                :page-sizes="[5, 10, 20, 40]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
        </el-pagination>
    </div>
</div>

<script src="../../js/jquery.min.js"></script>
<script src="../../js/vue.min.js"></script>
<script src="../../js/element.js"></script>
<script src="../../js/tinymce/tinymce.min.js"></script>


<script>

    let urlBase = "/api/message/";
    new Vue({
        el: "#wrapper",
        data: {
            user: {},
            tableData: [],
            pageNum: 1,
            pageSize: 10,
            total: 0,
            dialogFormVisible: false,
            entity: {},
            isCollapse: false,
            search: '',
            options: [],
        },
        created() {
            this.user = sessionStorage.getItem("user") ? JSON.parse(sessionStorage.getItem("user")) : {};
            this.loadTable();
        },
        methods: {
            handleCollapse() {
                this.isCollapse = !this.isCollapse;
            },
            logout() {
                // 请求退出接口
                $.get("/api/user/logout");
                localStorage.removeItem("user");
                location.href = "/page/end/login.html";
            },
            loadTable() {
                $.get(urlBase + "/page?pageNum=" + this.pageNum + "&pageSize=" + this.pageSize + "&name=" + this.search).then(res => {
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                });
            },
            exp() {
                window.open(urlBase + "/export");
            },
            handleSizeChange(pageSize) {
                this.pageSize = pageSize;
                this.loadTable();
            },
            handleCurrentChange(pageNum) {
                this.pageNum = pageNum;
                this.loadTable();
            },

            del(id) {
                $.ajax({
                    url: urlBase + id,
                    type: "delete"
                }).then(res => {
                    if (res.code === '0') {
                        this.$message({
                            message: "删除成功",
                            type: "success"
                        });
                        this.loadTable();
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        })
                    }
                })
            }
        }
    })
</script>
</body>
</html>
